package top.pcat.config;

import lombok.Data;
import top.pcat.Server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class RedisConfig {

    private String host;
    private int port;
    private int timeout;
    private String password;
    private int jedisPoolMaxIdle;
    private Boolean jedisPoolTestOnBorrow;
    private int jedisPoolMaxTotal;

    public RedisConfig() throws IOException {
        InputStream inputStream = Server.class.getClassLoader().getResourceAsStream("server.properties");
        Properties properties = new Properties();
        properties.load(inputStream);

        this.host = properties.getProperty("redis.host");
        this.port = Integer.parseInt(properties.getProperty("redis.port"));
        this.timeout = Integer.parseInt(properties.getProperty("redis.timeout"));
        this.password = properties.getProperty("redis.password");
        this.jedisPoolMaxIdle = Integer.parseInt(properties.getProperty("redis.jedisPool.maxIdle"));
        this.jedisPoolTestOnBorrow = Boolean.parseBoolean(properties.getProperty("redis.jedisPool.poolTestOnBorrow"));
        this.jedisPoolMaxTotal = Integer.parseInt(properties.getProperty("redis.jedisPool.maxTotal"));
    }

}
